<?php
class m_pembobotan_alternatif extends Model{
    var $table = 'bobot_alternatif';
    function getListBobot(){
        $qAdikAsuh = $this->db->query("select id from adik_asuh where status = '0' order by nama asc");
        $qKriteria = $this->db->query("select id from kriteria");
        $i = 0;
        foreach ($qAdikAsuh->result_array() as $row){
            $j = 0;
            foreach ($qKriteria->result_array() as $rows){
                $qBobot = $this->db->query("select * from bobot_alternatif where id_calon_adik_asuh = '$row[id]' and id_kriteria = '$rows[id]'");
                foreach ($qBobot->result_array() as $bobot){
                    $bobots[$i][$j] = $bobot['bobot'];
                }
                $j++;
            }
            $i++;
        }
        return $bobots;
    }
    function getBobotByCalonAdikAsuh($idCalonAdikAsuh){
        $query = $this->db->query("select ba.*,k.nama as kriteria from bobot_alternatif ba join kriteria k on ba.id_kriteria = k.id where ba.id_calon_adik_asuh = '$idCalonAdikAsuh'");
        if($query->num_rows() > 0){
            $return = $query->result_array();
        }else $return = array();
        return $return;
    }
    function editBobotAlternatif($id,$bobot){
        $i = 0;
        foreach ($id as $row){
            $insert = $this->db->query("update bobot_alternatif set bobot = '$bobot[$i]' where id = '$row'");
            $i++;
        }
        if($insert){
            return TRUE;
        }else return FALSE;
    }
}
?>
